import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_riverpod_test/manager/app_manager.dart';
import 'package:flutter_riverpod_test/model/product.dart';
import 'package:flutter_riverpod_test/view/home/home_cart_list_item.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

import '../../model/cart.dart';
import 'home_cart_list_panel.dart';
import 'home_product_panel.dart';

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  /// 添加购物车
  void addCartAction() {
    AppManager.shared.addCart();
  }

  @override
  Widget build(BuildContext context) {
    Color primaryColor = Theme.of(context).colorScheme.primary;
    return Scaffold(
      appBar: AppBar(
        backgroundColor: primaryColor,
        title: const Text("首页"),
      ),
      backgroundColor: Colors.white,
      body: SafeArea(
        child: Column(
          children: [
            DecoratedBox(
              decoration: BoxDecoration(
                color: primaryColor.withOpacity(0.15),
              ),
              child: const HomeProductPanel(),
            ),
            const Expanded(
              child: HomeCartListPanel(),
            ),
            Container(
              width: double.infinity,
              height: 50,
              decoration: BoxDecoration(
                  border: Border(
                    top: BorderSide(
                        color: primaryColor,
                        width: 0.5
                    ),
                    left: BorderSide.none,
                    right: BorderSide.none,
                    bottom: BorderSide.none,
                  )
              ),
              child: Center(
                child: Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 15),
                  child: ElevatedButton(
                    onPressed: addCartAction,
                    child: const Text("添加购物车"),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

